class PartStylesController < ApplicationController
  before_action :set_menu

  def index
    @submenu = :part_style
    @title = '配件管理'
    @part_styles = PartStyle.all
  end

  def new
    @part_style = PartStyle.new
  end

  def create
    @part_style = PartStyle.new post_params
    if @part_style.save
      redirect_to part_styles_path
    else
      render :action => 'new'
    end
  end

  def edit
    @part_style = PartStyle.find params[:id]
  end

  def update
    @part_style = PartStyle.find params[:id]
    if @part_style.update_attributes post_params
      redirect_to part_styles_path
    else
      render :action => 'edit'
    end
  end

  def show
    @title = "配件管理/明细"
    @buttons.push :action => part_styles_path, :label => "返回"
    @part_style = PartStyle.find params[:id]
  end

  def destroy
    @part_style = PartStyle.find params[:id]
    @part_style.destroy
    redirect_to part_styles_path
  end


  def post_params
    params.require(:part_style).permit(*%w(name))
  end

  private
  def set_menu
    @mainmenu = :part
  end
end
